<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找出数组中的幸运数</title>
</head>
<body>
  <script>
    var arr = [1, 2, 2, 3, 3, 3]
    function fn(arr) {
      let m = {}
      arr.forEach((x) => {
          m[x] = (x in m ? m[x] + 1 : 1)
          // console.log(m[x], x)
      })
      let res = -1
      // keys 获取所有属性
      // console.log(Object.keys(m))
      Object.keys(m).forEach((key) => {
          res = (key == m[key] ? Math.max(key, res) : res)
      })
      return res
    }
    console.log(fn(arr));
  </script>
</body>
</html>